package com.lazy.lib.db.bonecp;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.lazy.lib.db.DbUtil;
import com.lazy.lib.db.JDBCConfig;

/**
 * 连接单个数据库类的封装
 * 
 * @author luodan
 *
 */
public class SingleDBImpl extends BaseDBImpl {
    private final static Logger logger = LoggerFactory.getLogger(SingleDBImpl.class);
    
    protected DBConnPool conPool;
    protected JDBCConfig config;
    
    public SingleDBImpl(JDBCConfig config){
        this.config = config;
        // logger.info("{} created.", this.getClass().getName());
    }
    
    protected DBConnPool getConnPool() {
        if (conPool != null) {
            return conPool;
        }
        try {
            conPool = DBConnPools.getDbConnPool(config);
        } catch (ClassNotFoundException e) {
            logger.error("DBOper create ClassNotFoundException", e);
        } catch (SQLException e) {
            logger.error("DBOper create SQLException", e);
            checkSQLException(e, 0);
        }
        return conPool;        
    }
    
    @Override
    protected Connection getConnection(int poolFlag) throws SQLException{
        return getConnPool().getConnection();
    }
    
    public Date getDBsysTime() {
        return getDBsysTime(0);
    }
}
